<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="shortcut icon" type="image/png" href="/static/favicon.ico"/>
    <link rel="apple-touch-icon" href="/static/apple-touch-icon.png">
    <title>使用提现码</title>
    {% include 'link.html'%}
    <script>
        $(document).ready(function() {
            $("#withdraw_code_use").click(function()
            {
                on_code_submit();
            })
            $("#withdraw_code_check").click(function()
            {
                on_code_check();
            })
        })

        function on_code_submit()
        {
            $.post("https://NiuBiEX.com/btc/withdraw_legal_code_use",
            //$.post("http://localhost:8000/btc/withdraw_legal_code_use",
            $("#form_withdraw").serialize(),
            dataType:'JSONP',

            function(data){
                console.log("data "  + JSON.stringify(data))
                console.log("data "  + data.result)
                console.log("data "  + data.msg)
                //data {"result":false,"msg":"withdraw_amount_to_large"}
                if (data.result == true)
                {
                    $("#use_code_success").show()
                    $("#use_code_false").hide()
                }
                else
                {
                    $("#use_code_false").show()
                    $("#use_code_success").hide()
                    $("#use_code_msg").html(data.msg);
                }
            });
        }
        function on_code_check()
        {
            $.post("{%url 'code_check'%}",
            $("#form_withdraw").serialize(),
            function(data){
                console.log("data "  + JSON.stringify(data))
                console.log("data "  + data.result)
                console.log("data "  + data.msg)
                //data {"result":false,"msg":"withdraw_amount_to_large"}
                if (data.result == true)
                {
                    $("#msg").html("提现码有效");
                    $("#amount").html("提现码金额:$"+data.amount);
                    $("#amount_get").html("出售提现码得到:￥"+data.amount*6.6);
                    $("#error").html("");
                }
                else
                {
                    $("#msg").html("提现码无效");
                    if (data.msg == "code_has_used")
                    {
                        $("#error").html("该提现码已经被使用");
                    }
                    else
                    {
                        $("#error").html(data.msg);
                    }
                    $("#amount_get").html("");
                    $("#amount").html("");
                }
            });
        }
    </script>
</head>

<body>
{% include "header.html" %}
<div id="main">
    <div id="content">
        <div class="col-sm-12">
            <form class="form-horizontal" id="form_withdraw" method="post" role="form">
                {% csrf_token %}
                <div class="form-group">
                    <div class="col-sm-offset-1 col-sm-10 col-xs-10">
                        <div class="input-group">
                            <span class="input-group-addon green">提现码</span>
                            <input type="text" class="form-control" name="code" id="code">
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-1 col-sm-3 col-xs-3">
                        <button type="button" id="withdraw_code_check" class="btn btn-block btn-warning" data-toggle="tooltip">查询提现码金额</button>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-1 col-sm-7">
                        <h5 id="msg" class="red"></h5>
                        <h5 id="amount" class="green"></h5>
                        <h5 id="amount_get" class="green"></h5>
                        <h5 id="error" class="green"></h5>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-1 col-sm-10 col-xs-10">
                        <div class="input-group">
                            <span class="input-group-addon green">收款银行</span>
                            <select class="form-control" name="bank">
                                <option value="支付宝">支 付 宝</option>
                                <option value="工商银行">工商银行</option>
                                <option value="农业银行">农业银行</option>
                                <option value="建设银行">建设银行</option>
                                <option value="交通银行">交通银行</option>
                                <option value="招商银行">招商银行</option>
                                <option value="中国银行">中国银行</option>
                                <!--
                                <option value="CMBC">民生银行</option>
                                <option value="CEBBANK">光大银行</option>
                                <option value="CITIC">中信银行</option>
                                <option value="SPDB">浦发银行</option>
                                <option value="CIB">兴业银行</option>
                                <option value="GDB">广发银行</option>
                                <option value="SDB">深发银行</option>
                                <option value="SPABANK">平安银行</option>
                                <option value="POSTGC">邮政银行</option>
                                -->
                            </select>
                        </div>
                    </div>
                </div>
                <!--
                <div class="form-group">
                    <div class="col-sm-offset-1 col-sm-10 col-xs-6">
                        <div class="input-group">
                            <span class="input-group-addon green">开户行</span>
                            <input type="text" class="form-control" name="bank_branch" id="bank_branch">
                        </div>
                    </div>
                </div>
                -->
                <div class="form-group">
                    <div class="col-sm-offset-1 col-sm-10 col-xs-10">
                        <div class="input-group">
                            <span class="input-group-addon green">收款人账号</span>
                            <input type="text" class="form-control" name="bank_account" id="bank_account">
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-1 col-sm-10 col-xs-10">
                        <div class="input-group">
                            <span class="input-group-addon green">收款人姓名</span>
                            <input type="text" class="form-control" name="bank_account_name" id="bank_name">
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-1 col-sm-10 col-xs-10">
                        <div class="input-group">
                            <span class="input-group-addon green">联系人手机</span>
                            <input type="text" class="form-control" name="phone" id="phone"/>
                            <span class="input-group-addon red">转账异常的时候联系</span>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-1 col-sm-3 col-xs-3">
                        <button type="button" id="withdraw_code_use" class="btn btn-block btn-success" data-toggle="tooltip">出售提现码</button>
                    </div>
                </div>
                <div id="use_code_success" class="form-group" style="display:none">
                    <div class="col-sm-offset-1 col-sm-11">
                        <div class="alert alert-warning alert-dismissible" role="alert">
                            <h5>操作成功, 该提现码已经设置为已使用，将不会再次被使用:</h5>
                        </div>
                    </div>
                </div>
                <div id="use_code_false" class="form-group" style="display:none">
                    <div class="col-sm-offset-1 col-sm-11">
                        <div class="alert alert-warning alert-dismissible" role="alert">
                            <h5 id="withdraw_title">提现码使用失败!</h5>
                            <h5 class="green">错误信息:<span id="use_code_msg"></span></h5>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{%include 'sidebar.html'%}
{%include 'foot.html'%}
</div>
</body>
</html>
